<template>
    <div class="section-wrap" style="height:100%;padding-top: 40px;" v-loading="flag">
      <!-- 头部 -->
      <div class="headerBox">
      <div class="header"  >
        <x-icon type="ios-arrow-left" size="" class="icon-white" @click="goBack"></x-icon>待整改问题项
      </div>
      </div>
      <vue-better-scroll
        class="wrapper"
        ref="scrollqq"
        :scrollbar="scrollbarObj"
        :pullDownRefresh="pullDownRefreshObj"
        :pullUpLoad="pullUpLoadObj"
        :startY='parseInt(startY)'
        @pullingUp="onPullingUp"
      >


      <ul class="tabNav">
        <li v-for="(item,index) in tabList" :key="item" :class="activeIndex ==index ? 'tabActive':''" @click="activeIndex=index">{{item}}</li>
      </ul>
        <div class="form-section">
          <div class="form-item form-item-style1" @click="getCompany(0)">
            <div class="label-title">
              <label>被考核单位</label>
            </div>
            <div class="input_div">
              <input type="text"
                     v-model="params.checkDepartName"
                     :disabled="isDisabled" />
              <input type="hidden" v-model="params.departId" />
              <x-icon type="ios-arrow-right" size="22" class="icon-right" ></x-icon>
            </div>
          </div>


          <div class="form-item form-item-style1">
            <div class="label-title">
              <label>查询开始时间</label>
            </div>
            <group>
              <datetime v-model="startDate"  format="YYYY-MM-DD" clear-text="清除" @on-clear="clearStartDate"></datetime>
            </group>
          </div>
          <div class="form-item form-item-style1">
            <div class="label-title">
              <label>查询结束时间</label>
            </div>
            <group>
              <datetime v-model="endDate"  clear-text="清除" @on-clear="clearEndDate"></datetime>
            </group>
          </div>
          <p class="search-btn" @click="search">查询</p>
          <div class="info_div2">
            <div class="form-item">
              <div><span>待整改：{{totalCount}}个</span></div>
            </div>
          </div>
          <div class="project_div">
            <ul class="project_list">
              <li v-for='(item,index) in accpentlist' :key="index" @click="GetAssessmentInfo(item.id)">
                <div class="lf">
                  <p >{{item.questionDescribr}}</p>
                  <span>待整改</span>
                </div>
                <div class="rf">
                  <p class="project_time">{{item.rectificationDate | initDate}}</p>
                </div>
                <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
              </li>

            </ul>
          </div>
        </div>

      </vue-better-scroll>
      <div v-transfer-dom>
        <popup v-model="classValue" width="100%">
          <select-depart @nodeClick='selectedDepart'></select-depart>
        </popup>
      </div>
        </div>
</template>
<script>
  import selectDepart from "@commonComponents/selectDepart/selectDepart";
import treeClassify from "@commonComponents/treeClassify";
import formatDate from "../../utils/formatDate";
import VueBetterScroll from "vue2-better-scroll"
import {
  XHeader,
  Tabbar,
  TabbarItem,
  Group,
  Cell,
  TransferDom,
  PopupPicker,
  Popup,
} from "vux";
export default {
  directives: {
    TransferDom
  },
  data() {
    return {
      flag:false,
      tabList:['全部','我的'],
      activeIndex:0,
      index: 0,
      /*下拉刷新*/
      scrollbarObj:{fade:true},
      pullDownRefreshObj:false,
      pullUpLoadObj:{
        threshold:0,
        txt:{
          more:"加载更多",
          noMore:"没有更多数据了"
        }
      },
      startY:0,
      scrollToX:0,
      scrollToY:0,
      scrollToTime:700,
      totalCount: 0, //量化考试
      accpentlist: [],
      classValue: false,
      data: [],
      isDisabled:true,
      params: {
        type: "zg",
        userid: localStorage.userid,
        username: localStorage.useraccount,
        deptId:'',
        endDate:'',
        startDate:'',
        maxResultCount: 10,
        skipCount: 0,
      },
      startDate: new Date().getFullYear()+"-01-01",
      endDate:formatDate(new Date(),'yyyy-MM-dd'),
      selectDepartType: 0
    };
  },
  components: {
    treeClassify,VueBetterScroll,
    selectDepart,
    Popup,
    PopupPicker
  },
  filters: {
    initDate (val) {
      if (!val) {
        return val;
      } else {
        return val.substring(0, 10);
      }
    }
  },
  mounted(){
        this.accpentlist = [];
        let that = this;
        this.$bridge.registerHandler("setToken", function(data) {
                         that.$store.state.Authorization =
          "Bearer " + data;
          var str = window.location.href
          that.accpentlist = []
          if(str.indexOf('activeIndex')!= -1){
            that.activeIndex = str.split('?activeIndex=')[1]
            that.getData()
          }else{
            that.getData()
          }
            //这里data ioS返回的是token值(字符串)
        });

        this.connectWebViewJavascriptBridge(function(bridge) {
            bridge.registerHandler("setToken", function(data) {
                             that.$store.state.Authorization =
          "Bearer " + data;
          var str = window.location.href
          that.accpentlist = []
          if(str.indexOf('activeIndex')!= -1){
            that.activeIndex = str.split('?activeIndex=')[1]
            that.getData()
          }else{
            that.getData()
          }
                  //这里data android返回的是token值(字符串)

            });
        });
    },
  created() {
    var str = window.location.href
    this.accpentlist = []
    if(str.indexOf('activeIndex')!= -1){
      this.activeIndex = str.split('?activeIndex=')[1]
      this.getData()
    }else{
      this.getData()
    }

  },
  watch:{
    'activeIndex':function(){
      this.accpentlist=[]
      this.getData()
    }
  },
  methods: {
    connectWebViewJavascriptBridge(callback) {
            if (window.WebViewJavascriptBridge) {
                callback(WebViewJavascriptBridge);
            } else {
                document.addEventListener(
                "WebViewJavascriptBridgeReady",
                function() {
                    callback(WebViewJavascriptBridge);
                },
                false
                );
            }
        },
    search(){
     this.accpentlist=[]
      this.getData()
    },
    getCompany(type) {
      this.classValue = true;
      this.selectDepartType = type;
    },
    nodeClick(item) {
      if (
        item.departType == 6 ||
        item.departType == 7 ||
        item.departType == 8
      ) {

        this.param.deptId = item.id;
        this.classValue = false;
      } else {
        this.$vux.toast.text("只能选择项目部");
      }
    },
    selectedDepart(data) {
      this.params.deptId = data.id;
      if (this.selectDepartType == 0) {
        this.params.checkDepartName = data.departName;
      } else {
        this.params.beCheckDepartName = data.departName;
      }
      this.classValue = false;
    },
    getData() {


      var param1 = {
        type: "zg",
        // userid: this.activeIndex == 0 ? '' : localStorage.userid,
        skipCount: 0,
        endDate:'',
        deptId:this.params.deptId,
        startDate:'',
        maxResultCount: 10
      }
      if (this.startDate) {
        param1.startDate = this.startDate + " 00:00:00";
      }
      if (this.endDate) {
        param1.endDate = this.endDate + " 23:59:59";
      }

      if(this.activeIndex == 0){
        param1.userid=''
      }else{
        param1.userid=localStorage.userid
      }
      this.flag=true
      this.$axiosAjax.getBacklogList(param1).then(res => {
        this.flag=false
        this.totalCount = res.data.result.totalCount;
        let relist = res.data.result.items;
        if (this.params.skipCount == 0) {
          this.accpentlist = [];
        }
        this.accpentlist = this.accpentlist.concat(relist);
        let totalAllCount = res.data.result.totalCount;
        let resultCount = this.accpentlist.length;
        if (parseInt(resultCount) < parseInt(totalAllCount)) {
          this.$refs["scrollqq"].forceUpdate(true);
        } else {
          this.$refs["scrollqq"].forceUpdate(false);
        }
      });
    },
    GetAssessmentInfo(id) {
        this.$router.push({
          path: 'problemRectifyDetail', query: {
            id: id,
            index:this.activeIndex
          }
        })

    },
    getCompany(type) {
      this.classValue = true;
      this.selectDepartType = type;
    },
    clearStartDate() {
      this.startDate = "";
    },
    clearEndDate() {
      this.endDate = "";
    },
    onPullingUp() {

      let limitcount=this.accpentlist.length;
      this.params.skipCount=limitcount;
      // if (this.params.skipCount + this.params.maxResultCount < this.totalCount) {
      //   this.params.skipCount = this.params.skipCount + this.params.maxResultCount;
      this.getData();
      // }
    },
    onPullingDown() {
      // this.search();
    },
    goBack() {
      this.$bridge.callHandler({
              type: 'closePage',
              data: {}
            });
    }
  }
};
</script>
<style lang="less" scoped>
  .search-btn{
    width: 200px;
    line-height: 40px;
    border-radius: 20px;
    margin: 23px auto;
    color: #fff;
    background: #469b7a;
    text-align: center;
  }
  .tabNav{
    height: 40px;
    background: #fff;
    li{
      float:left;
      width:50%;
      line-height: 40px;
      height: 40px;
      text-align: center;
      border-bottom:1px solid #ededef;
    }
    .tabActive{
      background: #ededef;
    }
  }

.form-item {
  .input_div {
    .vux-x-icon {
      fill: #999;
      float: right;
      margin-top: 17px;
    }
  }
}
  .rf{
    float:right;
    height: 100%;
    width: 30%;
    display: flex;
    align-items: center;
    p{
      height:50px;
      line-height: 50px;

    }
  }
  .lf{
    float: left;
    height: 100%;
    width: 70%;
    line-height: 25px;
    display:flex;
    align-items: center;
    img{
      width:40px;
      height:40px;
      float:left;
      margin-right:10px;
    }
    p{
      width:130px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp:2;
      -webkit-box-orient:vertical;
      float:left;
    }
    span{
      float:left;
    }
  }
  .project_div {
    .project_list

    {
      box-sizing: border-box;
      padding-left: 10px;
      li

      {
        border-bottom: 1px solid #efeff4;
        height: 77px;
        position: relative;
        padding-top: 10px;
        padding-right: 22px;
        h4

        {
          width: calc(100% - 50px);
          text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden;
          font-size: 16px;
          margin-bottom: 8px;
          font-weight: bold;
        }

        p {
          span

          {
            font-size: 14px;
            color: #666;
          }

          span:first-child {
            margin-right: 40px;
          }

        }

        .project_status {
          margin-top: 14px;
          strong

          {
            font-size: 12px;
          }

          strong.project_status1 {
            color: #ff7333;
          }

          strong.project_status2 {
            color: #469b7a;
          }

        }

        .vux-x-icon {
          fill: #999;
          float:right;
          margin-top:-42px;
        }

      }
    }
  }
.add_btn {
  position: fixed;
  height: 62px;
  width: 62px;
  right: 30px;
  bottom: 35px;
}
</style>
